package com.itqf.controller;

import com.itqf.entity.TbItem;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/12/23
 * @Time: 上午11:01
 */
@RestController
public class MyController {

    @Resource
    private EurekaClient eurekaClient;//
    @Resource
    private RestTemplate restTemplate;


    @RequestMapping(value = "/find",produces = "application/json")
    public   String  find(){

        //1.返回eureka服务中eureka_client_provider该应用的实例信息
        InstanceInfo instanceInfo  =  eurekaClient.getNextServerFromEureka("eureka_client_provider",false);
        //2.得到该应用的地址
        String url = instanceInfo.getHomePageUrl();
        //http://127.0.0.1:8082
        System.out.println("url:"+url);

        //3.调用服务
        //请求地址，并且把该地址的响应参数 转成参数二类型
        TbItem tbItem = restTemplate.getForObject(url+"/find/1",TbItem.class);
        System.out.println(tbItem);
        return "结果："+tbItem.toString();

    }


}
